package com.yanqu.road.server.cmd.group.rank;

import com.yanqu.road.logic.cross.CrossGroupUnionRankListModel;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.pb.rank.RankProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.rank.CrossRankMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = CrossProtocol.C_CROSS_GROUP_UNION_RANK,desc = "分组商会榜单")
public class GetCrossGroupUnionRankCmd extends CrossCommand {
    private long userId;
    private int groupId;
    private String unionId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        RankProto.CrossGroupUnionRankReqMsg req = RankProto.CrossGroupUnionRankReqMsg.parseFrom(packet.getBytes());
        userId = packet.getPlayerId();
        groupId = req.getGroupId();
        unionId = req.getUnionId();
        if(0 == groupId){
            return false;
        }
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        CrossGroupUnionRankListModel rankListModel = CrossRankMgr.getAllCrossGroupUnionRankListModelMap().get(groupId);
        if(null == rankListModel){
            log.info("GroupUnionRankList error,serverId:{},userId:{},groupId:{}", serverId, userId, groupId);
            return;
        }
        RankProto.UnionRankListMsg.Builder unionListMsg = rankListModel.getRankListMsg();
        RankProto.UnionRankRespMsg.Builder respMsg = RankProto.UnionRankRespMsg.newBuilder();
        respMsg.setRankList(unionListMsg);
        int myRank = rankListModel.getMyRank(unionId);
        respMsg.setMyRank(myRank);
        YanQuMessage message = YanQuMessageUtils.buildMessage(Protocol.U_UNION_RANK_LIST, respMsg);
        MessageHelper.sendPacket(serverId, userId, message);
    }

    @Override
    public void sendData() {

    }
}
